﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.UpdateContinuousMfg.CApUCMUpdateContinuousMfgExposedTCLogic
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.UpdateContinuousMfg;

internal class CApUCMUpdateContinuousMfgExposedTCLogic : CApUCMUpdateContinuousMfgTCLogic
{
  private TxTypeFilterValidator _processValidator;

  public CApUCMUpdateContinuousMfgExposedTCLogic() => this.InitSelectedMfg();

  private ITxPlanningObject GetPlanningRepresentation(ITxObject obj)
  {
    switch (obj)
    {
      case ITxProcessModelObject processModelObject:
        pattern_0 = processModelObject.PlanningRepresentation;
        break;
    }
    return pattern_0;
  }

  public ITxValidator GetTCProcessValidator()
  {
    if (this._processValidator == null)
      this._processValidator = new TxTypeFilterValidator((ITxTypeFilter) new TxTypeFilter(typeof (TxTcProcess)));
    return (ITxValidator) this._processValidator;
  }

  public TxObjectList GetTCProcessList()
  {
    return TxApplication.ActiveDocument.OperationRoot.GetAllDescendants((ITxTypeFilter) new TxTypeFilter(typeof (TxTcProcess)));
  }

  public TxTcProcess GetRootProcess()
  {
    TxObjectList directDescendants = TxApplication.ActiveDocument.OperationRoot.GetDirectDescendants((ITxTypeFilter) new TxTypeFilter(typeof (ITxCompoundOperation)));
    return directDescendants == null || ((Collection<ITxObject>) directDescendants).Count <= 0 ? (TxTcProcess) null : ((Collection<ITxObject>) directDescendants)[0] as TxTcProcess;
  }

  public void StoreJtOnProcess(ITxObject processObject)
  {
    TxSeamMfgFeatureEx seamMfgFeatureEx = new TxSeamMfgFeatureEx(this.SelectedSeam);
    if (!seamMfgFeatureEx.IsLocal)
      return;
    try
    {
      string str = seamMfgFeatureEx.SaveComponent();
      ITxPlanningObject planningRepresentation = this.GetPlanningRepresentation(processObject);
      if (planningRepresentation != null)
      {
        TxTcFileAttachmentData fileAttachmentData = new TxTcFileAttachmentData(str, this.CreateDataSetName());
        new TxPlanningObjectEx(planningRepresentation).AttachEndModelingFilesOnObject((ITxObject) this.SelectedSeam, (TxFileAttachmentData) fileAttachmentData);
      }
      TxApplication.ActiveDocument.UndoManager.ClearAllTransactions();
    }
    catch (Exception ex)
    {
      TxApplication.LogWriter.WriteExceptionLine(ex);
      int num = (int) TxMessageBox.Show(ex.Message, StringTable.ResourceManager.GetString("END_MODELING_CMD_NAME"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  public bool ShouldEnableOKButton(
    ITxObject curve,
    ITxObject process,
    bool isAddChangesToProcessSelected,
    bool isUpdateChangesToRevision,
    bool isRestoreGeometrySelected)
  {
    bool flag = false;
    if (!isRestoreGeometrySelected)
    {
      if (this.ShouldEnableOKButton(curve))
      {
        if (isAddChangesToProcessSelected)
        {
          if (process != null)
            flag = true;
        }
        else
          flag = true;
      }
    }
    else
      flag = true;
    return flag;
  }

  public bool ShouldEnableRestoreGeometryOfItemRevisionCheckbox()
  {
    bool flag = false;
    TxSeamMfgFeatureEx seamMfgFeatureEx = new TxSeamMfgFeatureEx(this.SelectedSeam);
    if (seamMfgFeatureEx != null && seamMfgFeatureEx.IsLocal)
      flag = true;
    return flag;
  }
}
